﻿@using KRM.Core
@using KRM.Core.Library
@model IEnumerable<KRM.Core.vWebEmailTicket>
@{
    var count = ViewBag.PagingCount;
    var page = ViewBag.Page;
    var statusid = ViewBag.FilterStatusId ?? "null";
    var departmentid = ViewBag.DepartmentID ?? "null";
    var total = ViewBag.Total;
    var itemShow = ViewBag.Item;
}

<form method="POST" class="margin0" id="fr-listticket">
    <input type="hidden" name="statusid" value="@statusid"/>
    <input type="hidden" name="departmentid" value="@departmentid"/>

    <div class="listticketresult scrollable" data-visible="true">
        <table class="table table-fix table-ticket">
            <thead>
                <tr>
                    <th><input type="checkbox" class="checkallticket" name="checkall" style="margin-left: 5px;" /></th>
                    <th style="padding-right: 0px; width: 10px;"></th>
                    <th style="text-align: center; cursor: pointer" onclick="sortticket($(this),'@statusid', '@departmentid', $('#divListTicket'));" data-sort="@ViewBag.Sort">ID</th>
                    <th onclick="sortticket($(this),'@statusid', '@departmentid', $('#divListTicket'));" data-sort="@ViewBag.Sort" style="cursor: pointer">Subject</th>
                    <th onclick="sortticket($(this),'@statusid', '@departmentid', $('#divListTicket'));" data-sort="@ViewBag.Sort" style="cursor: pointer">Requester</th>
                    <th onclick="sortticket($(this),'@statusid', '@departmentid', $('#divListTicket'));" data-sort="@ViewBag.Sort" style="cursor: pointer">Requested</th>
                    <th onclick="sortticket($(this),'@statusid', '@departmentid', $('#divListTicket'));" data-sort="@ViewBag.Sort" style="cursor: pointer">Assigned To</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    var statusClass = "";
                    switch (item.StatusID)
                    {
                        case (int)TicketStatus.New:
                            statusClass = "label-warning";
                            break;
                        case (int)TicketStatus.Assigned:
                            statusClass = "label-important";
                            break;
                        case (int)TicketStatus.Pending:
                            statusClass = "label-info";
                            break;
                        case (int)TicketStatus.Solved:
                            statusClass = "label-inverse";
                            break;
                        case (int)TicketStatus.Closed:
                            statusClass = "";
                            break;
                        case (int)TicketStatus.Started:
                            statusClass = "label-success";
                            break;
                        case 7:
                            statusClass = "label-blue";
                            break;
                    }
                    <tr@(item.IsRead == false ? " class=bold" : "")  title="@item.Subject - @item.EmailFrom">
                        <td><input type="checkbox" name="ticketid" value="@item.TicketID"/></td>
                        <td style="@(item.TypeId == 2 ? "border-left:solid 5px #F30F4B" : "")" onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')">
                            <span class="label @statusClass">@item.Status.Substring(0, 1)</span>
                            <span>@if (item.ReplyStatusId == 1)
                                  {
                                <i class="icon-arrow-left" style='color: green'></i>
                                  }
                                  else
                                  {
                                <i class="icon-arrow-right" style='color: red'></i>
                                  }</span>
                        </td>
                        <td @*class="showSummary" data-id="data_@item.TicketID"*@ style="text-align: center" onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')" >#@item.TicketID
                            @*<div id="data_@item.TicketID" class="hidden-tip" data-emailid="@item.OriginalEmailID">
                                <div class="protip-title">
                                    <span class="label @statusClass">@item.Status </span><strong>Ticket#@item.TicketID @item.Subject</strong>
                                </div>
                                <div class="protip-content">
                                     @Html.Raw(item.EmailBody)
                                </div>
                            </div>*@
                        </td>
                        <td onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')">@item.Subject</td>
                        <td onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')">@item.EmailFrom</td>
                        <td onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')">@string.Format("{0:dd/MM/yyyy hh:mm}", item.DateAdded)</td>
                        <td onclick="viewticket('@item.TicketID', '@((item.Subject ?? " ").Replace("'", "\'"))')">@item.AssignToUserName</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    @if (count > 1)
    {
        <div class="pagination text-center page-ticket">
            <div class="row-fluid">
                <div class="span3 bold text-right" style="line-height: 30px;">
                    @((page * itemShow) - itemShow + 1) <span style="font-weight: normal">-</span> @((page * itemShow)) <span style="font-weight: normal">of</span> @total
                </div>
                <div class="span6">
                    <ul>
                        <li><a href="javascript:;" onclick="ticketpaging(1,@departmentid,@statusid)">«</a></li>
                        @for (int j = page - 3; j <= page + 3; j++)
                        {
                            if (j > 0 && j <= count)
                            {
                                if (j == page)
                                {
                            <li class="active"><a href="javascript:;" onclick="ticketpaging(@j,@departmentid,@statusid)">@j</a></li>
                                }
                                else
                                {
                            <li><a href="javascript:;" onclick="ticketpaging(@j,@departmentid,@statusid)">@j</a></li>
                                }

                            }
                        }
                        <li><a href="javascript:;" onclick="ticketpaging(@count,@departmentid,@statusid)">»</a></li>
                    </ul>
                </div>
            </div>
        </div>
    }
</form>
